// JointRegular.cpp: implementation of the JointRegular class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "JointRegular.h"
#include "FirstFixNextUnfix.h"
#include "Joint.h"
#include "JointFunction.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNAMIC_EX(JointRegular, UeObject)

JointRegular::JointRegular()
{
	m_pJoint = NULL;
}

JointRegular::~JointRegular()
{

}

DWORD JointRegular::RegularSerialNumGenerator(INT nFirstJointNum, INT nAfterJointNum)
{
	DWORD dResult = 0;
	dResult = (nFirstJointNum<<16)|nAfterJointNum;
	return dResult;
}

CStringArray* JointRegular::GetSizeRangeText(JointSystem::RealTextExpSet& text)
{
	if(text.IsUnknown())
		return NULL;

	CString strTemp;
	CStringArray* pstrArr = new CStringArray;
	if(text.GetValue().GetExtentCount() != 0)
	{
		strTemp = text.GetValue().GetExtentAt(0).m_etUpperBound.operator CString();
		pstrArr->Add(strTemp);
		strTemp = text.GetValue().GetExtentAt(0).m_etLowerBound.operator CString();
		pstrArr->Add(strTemp);
	}
	else if(text.GetValue().GetCollection().GetElementCount() != 0)
	{
		strTemp = text.GetValue().GetCollection().GetElementAt(0).operator CString();
		pstrArr->Add(strTemp);
	}

	return pstrArr;
}

void JointRegular::GenerateJointState(JointState& FirstFixNextUnfixState, JointState& AllFixState)
{
	ASSERT(m_pJoint);
	ASSERT(m_pJoint->GetPrev());
	ASSERT(m_pJoint->GetNext());
	BOOL bFirstPartState = this->m_pJoint->GetPrev()->IsInstantiation();
	BOOL bNextPartState = this->m_pJoint->GetNext()->IsInstantiation();
	
	ASSERT(bFirstPartState || bNextPartState);
	ASSERT(bFirstPartState);

	if(bFirstPartState && !bNextPartState)
	{
		FirstFixNextUnfixState.SetJointRegular(this);
		SetJointState(&FirstFixNextUnfixState);
	}
	else if(bFirstPartState && bNextPartState)
	{
		AllFixState.SetJointRegular(this);
		SetJointState(&AllFixState);
	}
}